import java.text.DateFormat;
import java.time.*;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        System.out.println("========默认SimpleDateFormat========");
        SimpleDateFormat sdf = new SimpleDateFormat();
        String date = sdf.format(new Date());
        System.out.println(date);
        System.out.println("===================================");

        System.out.println("===========指定SimpleDateFormat========");
        SimpleDateFormat sdf_test = new SimpleDateFormat("yyyy-MM-dd");
        date = sdf_test.format(new Date());
        System.out.println(date);
        System.out.println("===================================");

        System.out.println("===========自定SimpleDateFormat========");
        SimpleDateFormat sdf1 = new SimpleDateFormat("Gyyyy-MM-dd EEE");
        date = sdf1.format(new Date());
        System.out.println(date);
        System.out.println("===================================");

        System.out.println("=============LocalDateTime自定时间============");

        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("当前时间" + localDateTime);

        LocalDate date1 = LocalDate.now();
        LocalDate date2 = localDateTime.toLocalDate();
        System.out.println("当前日期1:" + date1);
        System.out.println("当前日期2:" + date2);

        Month month = localDateTime.getMonth();
        int day = localDateTime.getDayOfMonth();
        int seconds = localDateTime.getSecond();
        System.out.println("月" + month + "日" + day + "秒" + seconds);

        LocalDateTime localDateTime1 = localDateTime.withDayOfMonth(10).withYear(2023);
        System.out.println("修改后的时间" + localDateTime1);

        System.out.println("===================================");

        System.out.println("=============LocalDate自定时间============");
        LocalDate localDate = LocalDate.of(2023, Month.JANUARY, 1);
        System.out.println("自定义时间" + localDate);
        localDate = LocalDate.of(2023, 1, 1);
        LocalTime date4 = LocalTime.of(22,15);
        System.out.println("date4" + date4);
        LocalTime date5 = LocalTime.parse("20:15:30");
        System.out.println("date5" + date5);
        System.out.println("===================================");


        System.out.println("=============ZonedDateTime自定时间============");
        //        ZonedDateTime date1 = ZonedDateTime.now();
        ZonedDateTime date1s = ZonedDateTime.parse("2023-08-10T15:01:41+05:30[Asia/Shanghai]");
//        ZonedDateTime date1 = ZonedDateTime.parse("2023-08-10T15:09:18.662+08:00[Asia/Shanghai]");

        System.out.println("date1s" + date1);

        ZoneId id = ZoneId.of("Europe/Paris");
        System.out.println("ZoneId:" + id);

        ZoneId currentZone = ZoneId.systemDefault();
        System.out.println("当期时区" + currentZone);

        System.out.println("===================================");

        System.out.println("=============Calendar自定时间============");
        Calendar c = new Calendar() {//单个
            @Override
            protected void computeTime() {

            }

            @Override
            protected void computeFields() {

            }

            @Override
            public void add(int field, int amount) {

            }

            @Override
            public void roll(int field, boolean up) {

            }

            @Override
            public int getMinimum(int field) {
                return 0;
            }

            @Override
            public int getMaximum(int field) {
                return 0;
            }

            @Override
            public int getGreatestMinimum(int field) {
                return 0;
            }

            @Override
            public int getLeastMaximum(int field) {
                return 0;
            }
        };
        System.out.println("年" + c.get(Calendar.YEAR));
        System.out.println("月" + c.get(Calendar.MONTH));
        System.out.println("日" + c.get(Calendar.DAY_OF_MONTH));
        System.out.println("时" + c.get(Calendar.HOUR_OF_DAY));
        System.out.println("分" + c.get(Calendar.MINUTE));
        System.out.println("秒" + c.get(Calendar.SECOND));
        System.out.println("毫秒" + c.get(Calendar.MILLISECOND));

        DateFormat df1 = DateFormat.getDateInstance();
        DateFormat df2 = DateFormat.getDateTimeInstance();
        DateFormat df3 = DateFormat.getDateInstance(DateFormat.YEAR_FIELD,new Locale("zh","CN"));
        DateFormat df4 = DateFormat.getTimeInstance(DateFormat.ERA_FIELD,new Locale("zh","CN"));

        System.out.println(df1.format(new Date()));
        System.out.println(df2.format(new Date()));

        System.out.println(df3.format(new Date()));
        System.out.println(df4.format(new Date()));

        System.out.println("===================================");
    }
}